/*
 * Copyright 2006 Kevin Wetzels 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0 
 *       
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package be.roam.drest.service.bloglines;

import java.util.ArrayList;
import java.util.List;

import be.roam.util.StringUtil;

/**
 * A Bloglines subscription.
 */
public class BloglinesSubscription {

    private String title;
    
    private String urlHtml;
    
    private String urlXml;
    
    private String type;
    
    private long id;
    
    private int nrUnreadMessages;
    
    private boolean ignore;
    
    private List<BloglinesSubscription> subscriptionList;

    /**
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * @return the ignore
     */
    public boolean isIgnore() {
        return ignore;
    }

    /**
     * @param ignore the ignore to set
     */
    public void setIgnore(boolean ignore) {
        this.ignore = ignore;
    }

    /**
     * @return the nrUnreadMessages
     */
    public int getNrUnreadMessages() {
        return nrUnreadMessages;
    }

    /**
     * @param nrUnreadMessages the nrUnreadMessages to set
     */
    public void setNrUnreadMessages(int nrUnreadMessages) {
        this.nrUnreadMessages = nrUnreadMessages;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the type
     */
    public String getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(String type) {
        this.type = type;
    }

    /**
     * @return the urlHtml
     */
    public String getUrlHtml() {
        return urlHtml;
    }

    /**
     * @param urlHtml the urlHtml to set
     */
    public void setUrlHtml(String urlHtml) {
        this.urlHtml = urlHtml;
    }

    /**
     * @return the urlXml
     */
    public String getUrlXml() {
        return urlXml;
    }

    /**
     * @param urlXml the urlXml to set
     */
    public void setUrlXml(String urlXml) {
        this.urlXml = urlXml;
    }

    /**
     * @return the subscriptionList
     */
    public List<BloglinesSubscription> getSubscriptionList() {
        return subscriptionList;
    }

    /**
     * @param subscriptionList the subscriptionList to set
     */
    public void setSubscriptionList(List<BloglinesSubscription> entryList) {
        this.subscriptionList = entryList;
    }
    
    /**
     * Adds an entry.
     * 
     * @param entry entry to add.
     */
    public void addEntry(BloglinesSubscription entry) {
        if (subscriptionList == null) {
            subscriptionList = new ArrayList<BloglinesSubscription>();
        }
        subscriptionList.add(entry);
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof BloglinesSubscription) {
            return id == ((BloglinesSubscription) obj).id;
        }
        return false;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return (int) Math.min(id, Integer.MAX_VALUE);
    }
    
    /**
     * @return <code>true</code> if the XML URL is null or empty
     */
    public boolean isFolder() {
        return StringUtil.isNullOrEmpty(urlXml);
    }
    
}
